package com.guigu.www.cxk.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.www.cxk.service.CXKQuestionPgService;
import com.guigu.www.mapper.*;
import com.guigu.www.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CXKQuestionPgServiceImpl implements CXKQuestionPgService {
    @Autowired
    QuestionMapper questionMapper;

    @Autowired
    RubricMapper rubricMapper;

    @Autowired
    RubricOptionMapper rubricOptionMapper;

    @Autowired
    UserAnswerMapper userAnswerMapper;

    @Autowired
    ConstitutionTestMapper constitutionTestMapper;

    @Autowired
    MindTestMapper mindTestMapper;

    @Autowired
    RiskTestMapper riskTestMapper;

    @Autowired
    MemberMapper memberMapper;

    /*根据问卷的id查询题库*/
    @Override
    public List<Rubric> selectQub(int rid) {
       return rubricMapper.selectRubricByQuesId(rid);
    }

    /*根据评估类型id查询题目表在查询选项表*/
    @Override
    public List<RubricOption> SelectOption(int rid) {
        return rubricOptionMapper.SelectOption(rid);
    }

    @Override
    public int ListUserAwer(UserAnswer userAnswer) {
        return userAnswerMapper.insert(userAnswer);
    }

    @Override
    public Question selectQuestion(int rid) {
        return questionMapper.SelectQue(rid);
    }

    @Override
    public int saveQuestion(ConstitutionTest constitutionTest) {
        return constitutionTestMapper.insert(constitutionTest);
    }

    @Override
    public int saveMindTest(MindTest mindTest) {
        return mindTestMapper.insert(mindTest);
    }

    @Override
    public int saveRiskTest(RiskTest riskTest) {
        return riskTestMapper.insert(riskTest);
    }

    @Override
    public int updateByIdCon(ConstitutionTest constitutionTest,int mid) {
        QueryWrapper<ConstitutionTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id ",mid);
        return constitutionTestMapper.update(constitutionTest,wrapper);
    }

    @Override
    public int updateByIdMind(MindTest mindTest, int mid) {
        QueryWrapper<MindTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id ",mid);
        return mindTestMapper.update(mindTest,wrapper);
    }

    @Override
    public int updateByIdRisk(RiskTest riskTest, int mid) {
        QueryWrapper<RiskTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id ",mid);
        return riskTestMapper.update(riskTest,wrapper);
    }

    @Override
    public Member selectMember(int sid) {
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id",sid);
        return memberMapper.selectOne(wrapper);
    }

    @Override
    public ConstitutionTest selectByMid(int mid) {
        QueryWrapper<ConstitutionTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id",mid);
        return constitutionTestMapper.selectOne(wrapper);
    }

    @Override
    public MindTest selectByMind(int mid) {
        QueryWrapper<MindTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id",mid);
        return mindTestMapper.selectOne(wrapper);
    }

    @Override
    public RiskTest selectRisk(int mid) {
        QueryWrapper<RiskTest> wrapper = new QueryWrapper<>();
        wrapper.eq("mem_id",mid);
        return riskTestMapper.selectOne(wrapper);
    }

    @Override
    public UserAnswer selectByMid(Integer rid,Integer mid) {
        QueryWrapper<UserAnswer> wrapper = new QueryWrapper<>();
        wrapper.eq("rub_id ",rid).eq("mem_id",mid);
        return userAnswerMapper.selectOne(wrapper);
    }

    @Override
    public int DeleteByMid(Integer rid, Integer mid) {
        return userAnswerMapper.DeleteByMid(rid,mid);
    }
}
